#!/bin/sh
# Test runner
# Assumption is that this is run in the top-level directory

usage() {
	echo "Usage: $0 <test>"
}

run() {
	rm -rf ~/.angband/Test

	test="$1"
	printf "Running: $test... "
	src/angband -mtest -snone < "$test/input" > "$test/run.out"
	if [ -x "$test/matcher" ]; then
		"$test/matcher" "$test"
	else
		diff "$test/run.out" "$test/output" >/dev/null 2>/dev/null
	fi
	result=$?
	if [ $result -eq 0 ]; then
		printf "\033[01;32mPassed\033[00m\n"
	else
		printf "\033[01;31mFailed\033[00m\n"
	fi
	return $result
}

if [ $# -lt 1 ]; then
	usage
	exit 1
fi

run "$@"
